package sample.mailinglist;

import java.io.IOException;
import java.util.List;

import javax.jdo.PersistenceManager;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import sample.PMF;
import sample.User;

@SuppressWarnings("serial")
public class MailingListServlet extends HttpServlet {
  @SuppressWarnings("unchecked")
  public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
    
    PersistenceManager pm = PMF.get().getPersistenceManager();
    String query = "select from " + User.class.getName();
    List<User> users = (List<User>) pm.newQuery(query).execute();
    
    request.setAttribute("users", users);
    request.getRequestDispatcher("mailingList.jsp").forward(request, response);
  }
}
